package userlog

import (
	"context"
	"time"
	"trusteva/app/rbac/model"

	"trusteva/app/rbac/internal/svc"
	"trusteva/app/rbac/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLogDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserLogDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogDeleteLogic {
	return &UserLogDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserLogDeleteLogic) UserLogDelete(req *types.UserLogDeleteRo) (resp *types.BaseRsp, err error) {
	err = l.svcCtx.DB.WithContext(l.ctx).
		Where("CreatedAt>=?", time.Unix(req.Begin, 0).Format(time.RFC3339)).
		Where("CreatedAt<?", time.Unix(req.End, 0).Format(time.RFC3339)).
		Delete(&model.UserLog{}).Error

	return
}
